package jd.se.updateUserInfo;

import com.alibaba.fastjson.JSON;
import jd.se.common.CurrentUser;
import jd.se.common.Result;
import jd.se.common.Utils;
import jd.se.home.HomeService;
import jd.se.login.LoginDto;
import jd.se.login.LoginService;
import jd.se.returnrequest.ReturnRequestDao;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.*;
import java.util.UUID;

/**
 * @author SunJiahao
 * @date 2021-05-22 16:15
 */
@WebServlet({
        "/updateUserInfo",
})
public class UserInfoAPI extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getServletPath();
        if ("/updateUserInfo".equals(path)){
            String u_name = request.getParameter("u_name");
            String password = request.getParameter("password");
            String email = request.getParameter("email");
            String phone = request.getParameter("phone");
            SqlSession sess = Utils.openSession();
            UserInfoDao userInfoDao = sess.getMapper(UserInfoDao.class);
            CurrentUser currentUser = (CurrentUser)request.getSession().getAttribute(CurrentUser.SESSION_ATTR_NAME);
            String u_id = currentUser.getUserId();
            User user = new User(u_id,u_name,password,email,phone);
            userInfoDao.updateUserInfo(user);
            sess.commit();
        }
    }
}
